package com.hup.joystick.model.joystick;

import com.hup.joystick.constant.DeviceKey.KeyActionType;
import com.hup.joystick.service.jna.DInputHResultException.HResult;

import java.util.ArrayList;

/**
 * @author hugan
 * @date 2020/10/23
 */
public class StandardEvent {

    /**
     * 状态查询结果; {@link HResult}
     */
    public final int hr;

    /**
     * 当前按键(按钮,方向键,摇杆)事件:[新按下的,新抬起的],不包含[一直按下而改变值的摇杆事件]
     *
     * @apiNote 相当于androidx.appcompat.app.AppCompatActivity#dispatchKeyEvent:
     * .仅有摇杆最初按下的事件,摇杆抬起前的变化事件是不在这里反应的
     * .要在Activity#dispatchGenericMotionEvent()中才有摇杆值变化事件
     */
    public final ArrayList<StandardAction> actions = new ArrayList<>();
    /**
     * 当前被按下的按钮事件
     */
    public final ArrayList<StandardAction> currentPress = new ArrayList<>();

    public StandardEvent(int hr) {this.hr = hr;}

    @Override
    public String toString() {
        return "JoyActionEvent{" +
                "hr=" + hr +
                ", actions=" + actions +
                '}';
    }

    public static class StandardAction {
        public final StandardKey standardKey;
        /**
         * {@link KeyActionType}
         */
        public int actionType;

        public StandardAction(StandardKey standardKey, int actionType) {
            this.standardKey = standardKey;
            this.actionType = actionType;
        }

        @Override
        public String toString() {
            return "[" +
                    "key='" + standardKey.key + '\'' +
                    ", range=" + standardKey.range +
                    ", type=" + actionType +
                    ']';
        }
    }

}
